package com.wie.staffhubpro.controller;

import com.wie.staffhubpro.domain.dto.AttendanceDTO;
import com.wie.staffhubpro.domain.dto.CheckDTO;
import com.wie.staffhubpro.domain.entity.Attendance;
import com.wie.staffhubpro.domain.entity.Result;
import com.wie.staffhubpro.domain.vo.AttdDeptVO;
import com.wie.staffhubpro.service.AttendanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/attd")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;

    /**
     * 查看个人今日考勤
     */
    @GetMapping("/getToday")
    public Result getToday (@RequestParam String empId) {
        log.info("查看个人今日考勤: {}", empId);
        Attendance attendance = attendanceService.getToday(empId);
        return Result.success(attendance);
    }

    /**
     * 查看个人历史考勤
     */
    @PostMapping("/getHistory")
    public Result getHistory (@RequestBody AttendanceDTO attendanceDTO) {
        log.info("查看个人历史考勤: {}", attendanceDTO);
        List<Attendance> attendanceList = attendanceService.getHistory(attendanceDTO);
        return Result.success(attendanceList);
    }

    /**
     * 多条件查询部门考勤信息
     */
    @PostMapping("/getByDeptId")
    public Result getByDeptId (@RequestBody AttendanceDTO attendanceDTO) {
        log.info("多条件查询部门考勤信息: {}", attendanceDTO);
        List<AttdDeptVO> attdDeptVOList = attendanceService.getByDeptId(attendanceDTO);
        return Result.success(attdDeptVOList);
    }

    /**
     * 查询全部考勤信息
     */
    @PostMapping("/list")
    public Result getList (@RequestBody AttendanceDTO attendanceDTO) {
        log.info("查询全部考勤信息: {}", attendanceDTO);
        List<AttdDeptVO> attdDeptVOList = attendanceService.getList(attendanceDTO);
        return Result.success(attdDeptVOList);
    }

    /**
     * 员工签到
     */
    @PostMapping("/checkIn")
    public Result checkIn (@RequestBody CheckDTO checkDTO) {
        log.info("员工签到: {}", checkDTO);
        attendanceService.checkIn(checkDTO);
        return Result.success();
    }

    /**
     * 员工签退
     */
    @PostMapping("/checkOut")
    public Result checkOut (@RequestBody CheckDTO checkDTO) {
        log.info("员工签退: {}", checkDTO);
        attendanceService.checkOut(checkDTO);
        return Result.success();
    }

}
